package controller.link.game;

import view.client.Console;
import model.Hearer;
import java.io.Serializable;
import model.game.Item;
import controller.Link;
import controller.link.RefreshGameData;
import model.User;
import model.Attendant;
import model.Server;

public class UseItem implements Link, Serializable {

    private String itemName;
    private String move;

    public UseItem() {
    }

    public UseItem(Hearer h, String itemName) {
        this.itemName = itemName;
        h.send((Link) this);
    }

    @Override
    public void serverUse(Server server, Attendant at) {
        User user = at.getUser();
        Item item = user.getPlayer().findItem(this.itemName);
        item.use();
        move = user.getName() + " used " + item.getName();
        at.send((Link) this);
        RefreshGameData rgd = new RefreshGameData();
        rgd.serverUse(server, at);
    }

    @Override
    public void clientUse(Console console) {
        console.getPg().getTxtArea().append(move + "\n");
    }
}
